/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#include "SBJ/Arrow/Channel.h"
#include "MockMessage.h"

#include <boost/test/auto_unit_test.hpp>

BOOST_AUTO_TEST_CASE(NoDispatching)
{
	::printf("NoDispatching\n");
	// Create the channel
	SBJ::Arrow::Channel channel(  -1, -1 );
	channel.start();

	// Publish our message type
	SBJ::Arrow::Publication& pub = channel.publish< MockMessage >();

	// Creat the message
	volatile const char* hit = 0;
	MockMessage msg( hit, pub.getTopic< MockMessage >() );

	// Push the message
	channel.onMessage( msg );

	// And test
	::test_sleep( .5 );
	BOOST_CHECK_EQUAL( MockMessage::hit_none, const_cast<char*>(hit) );
}

BOOST_AUTO_TEST_CASE(ThreadExecute)
{
	::printf("Thread Execution\n");
	// Create the channel
	SBJ::Arrow::Channel channel( -1, 10 );
	channel.start();

	// Publish our message type
	SBJ::Arrow::Publication& pub = channel.publish< MockMessage >();

	// Create the message
	volatile const char* hit = 0;
	MockMessage msg( hit, pub.getTopic< MockMessage >() );
	msg.m_threadThreshold = 0;
	msg.m_blocks = false;

	// Push the message
	channel.onMessage( msg );

	// And test
	::test_sleep( .5 );
	BOOST_CHECK_EQUAL( MockMessage::hit_execute, const_cast< char* >( hit ) );
}
